#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<string>
using namespace std;

class Solution {
public:
    string reverseOnlyLetters(string s) {
        int left = 0, right = s.size() - 1;
        while (left < right)
        {
            while (left < right && !isalpha(s[left]))
            {
                left++;
            }
            while (left < right && !isalpha(s[right]))
            {
                right--;
            }
            swap(s[left++], s[right--]);
        }
        return s;
    }
};